<template>
  <div>
    <router-link tag="div" to="/" class="header-back" v-show="showHeaderBack">
      <span class="iconfont icon-back">&#xe624;</span>
    </router-link>
    <div class="header" :style="opacityStyle" v-show="!showHeaderBack">
      <router-link class="header-left" to="/">
        <span class="iconfont icon-back">&#xe624;</span>
      </router-link>
      长沙世界之窗
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      showHeaderBack: true,
      opacityStyle: {
        opacity: 0
      }
    };
  },
  activated() {
    window.addEventListener("scroll", this.handleScroll);
  },
  deactivated() {
    window.removeEventListener("scroll", this.handleScroll);
  },
  methods: {
    handleScroll() {
      let top = document.documentElement.scrollTop;
      if (top > 50) {
        let opacity = top / 130;
        this.opacityStyle.opacity = opacity > 1 ? 1 : opacity;
        this.showHeaderBack = false;
      } else {
        this.showHeaderBack = true;
      }
    }
  }
};
</script>

<style lang="stylus" scoped>
@import '~styles/variables.styl';

.header-back {
  position: absolute;
  top: .2rem;
  left: .2rem;
  width: .8rem;
  height: .8rem;
  line-height: .8rem;
  text-align: center;
  border-radius: .4rem;
  background-color: rgba(0, 0, 0, .8);
}

.header-back .icon-back {
  color: #fff;
}

.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: $headerHt;
  line-height: $headerHt;
  text-align: center;
  background-color: $bgcolor;
  color: #fff;
  z-index: 2;
}

.header .header-left {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-block;
  width: .8rem;
  height: 100%;
  text-align: center;
  color: #fff;
}
</style>
